<?php

namespace yiike\store\model;

use Yii;
use \yiike\store\model\base\Store as BaseStore;
use yii\helpers\ArrayHelper;
use trntv\filekit\behaviors\UploadBehavior;
/**
 * This is the model class for table "ims_ttyc_stores".
 */
class Store extends BaseStore
{
    public $logo_file;
    public $imagearr;
    public $province;
    public $city;
    public $district;
    public function behaviors()
    {
        return ArrayHelper::merge(
            parent::behaviors(),
            [

                [
                    'class' => UploadBehavior::className(),
                    'attribute' => 'logo_file',
                    'pathAttribute' => 'logo',
                ],
                [
                    'class' => UploadBehavior::className(),
                    'attribute' => 'imagearr',
                   // 'pathAttribute' => 'images',
                ],
            ]
        );
    }
    public function attributeLabels()
    {
        $attributeLabels = parent::attributeLabels();
        $attributeLabels['description'] = '描述';
        return $attributeLabels; // TODO: Change the autogenerated stub
    }
    public function rules()
    {
        return [
            [['weid', 'uid', 'cityid', 'type', 'pcate', 'ccate', 'level', 'isfirst', 'top', 'mode', 'checked', 'status', 'displayorder', 'isvip', 'vip_start', 'vip_end', 'max_sub', 'maker_id', 'company_id', 'commission_rate', 'service_rate', 'sold'], 'integer'],
            [['uid', 'address', 'discounts', 'consume', 'service_rate'], 'required'],
            [['description', 'images'], 'string'],
            [['lat', 'lng', 'shop_quan_rate', 'combo'], 'number'],
            [['wx_mchid', 'alipay_mchid', 'username', 'tel', 'consume', 'bank_account'], 'string', 'max' => 20],
            [['title', 'from_user', 'bank', 'payee'], 'string', 'max' => 50],
            [['logo_file','imagearr', 'images'], 'safe'],
            [['logo', 'services', 'address', 'discounts', 'place', 'hours', 'businesslicense'], 'string', 'max' => 200],
            [['starttime', 'endtime'], 'string', 'max' => 10],
            [['location_p', 'location_c', 'location_a', 'bank_sub'], 'string', 'max' => 100],
            [['pcate'], 'exist', 'skipOnError' => true, 'targetClass' => \yiike\store\model\TtycCategory::className(), 'targetAttribute' => ['pcate' => 'id']],
            [['ccate'], 'exist', 'skipOnError' => true, 'targetClass' => \yiike\store\model\TtycCategory::className(), 'targetAttribute' => ['ccate' => 'id']]
        ];
    }
    public function beforeSave($insert)
    {

        foreach($this->imagearr as $k=>$v){
            $arr[$k] = $v['path'];
        }
        $arr=implode('|',$arr);
        $this->images = $arr;
        return parent::beforeSave($insert); // TODO: Change the autogenerated stub
    }
    function afterFind()
    {
        $arr = explode('|',$this->images);
        foreach($arr as $k=>$v){
            $images[$k]['path'] = $v;
            $images[$k]['base_url'] = Yii::getAlias('@storageUrl/source');
        }

        $this->imagearr = $images ;
        parent::afterFind(); // TODO: Change the autogenerated stub
    }

}
